<template>
  <div class="page">
    <div class="s-search p20">
      <el-form
        :model="alone.searchForm.data"
        status-icon
        ref="ruleForm"
        :inline="true"
        class="demo-ruleForm"
      >
        <el-form-item>
          <el-input
            placeholder="请输入运营昵称/姓名搜索"
            v-model="alone.searchForm.data.searchStr"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入主播昵称搜索"
            v-model="alone.searchForm.data.searchStr"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入主播号搜索"
            v-model="alone.searchForm.data.searchStr"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="rSubmitSearchForm">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="c-main p20">
      <div class="clearfix">
        <div class="fl">总共：{{ pageAjax.paging.total }} 条</div>
      </div>
      <div class="c-section">
        <div class="c-body">
          <el-table :data="pageAjax.data" stripe style="width: 100%">
            <el-table-column label="头像">
              <template slot-scope="scope">
                <img class="c-avatar" :src="scope.row.avatarUrl" alt="" />
              </template>
            </el-table-column>
            <el-table-column prop="nickName" label="主播昵称">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.nickName }}
                  <span v-if="scope.row.hasLiveExperience" class="text-warning"
                    >(有直播经验)</span
                  >
                  <span v-else>(无直播经验)</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="平台">
              <template slot-scope="scope">
                <div class="text-abbreviate">
                  {{ scope.row.intentionPlatform || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="主播号">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.nickName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="所属运营">
              <template slot-scope="scope">
                <div class="">
                  {{
                    scope.row.operator && scope.row.operator.nickName
                      ? scope.row.operator.departmentName +
                        "-" +
                        scope.row.operator.nickName
                      : "无"
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="经纪转让权费用金额(元)">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.nickName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="创建时间">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.nickName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="录入时间">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.nickName }}
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="c-footer">
          <div class="c-pagination">
            <el-pagination
              layout="prev, pager, next"
              @current-change="rPagingChange"
              @prev-click="rPagingChange"
              @next-click="rPagingChange"
              :current-page="pageAjax.paging.current"
              :total="pageAjax.paging.total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getBiPlatformList } from "@/api/others.js";
import { getActorList, cancelBindActor } from "@/api/actor.js";
import { mixin } from "@/components/mixin/getSalaryStr.js";
import _ from "lodash";

export default {
  name: "agent_signedList",
  mixins: [mixin],
  data: () => ({
    pageAjax: {
      btnDisabled: false,
      btnLoading: false,
      loading: false,
      lock: false,
      paging: {
        pages: 1, // 总页数
        current: 0, // 当前页
        total: 1, // 总数量
        pageSize: 10 // 每页数量
      },
      data: []
    },
    biPlatformListSupAjax: {
      data: []
    },
    alone: {
      signStatus: "SIGNED",
      searchForm: {
        loading: false,
        data: {
          searchStr: "",
          tenantType: "3",
          relType: 2
        }
      }
    },
    translate: {
      biPlatformList: {}
    }
  }),
  created() {
    let _that = this;
    _that.getBiPlatformListData().then(() => {
      _that.getPageData();
    });
  },
  mounted() {},
  methods: {
    rSubmitSearchForm() {
      let _that = this;
      if (_that.pageAjax.loading) {
        return;
      }
      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      // if (!searchForm.data.searchStr && !searchForm.data.signWish && !searchForm.data.platform) {
      //   _that.$message.error({message: "搜索条件不能都为空", onClose: () => {
      //     _that.alone.searchForm.loading = false;
      //   }});
      //   return;
      // }
      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      _that.getPageData();
    },
    rPagingChange(e) {
      let _that = this;
      _that.pageAjax.paging.current = e - 1;
      _that.getPageData();
    },
    getBiPlatformListData() {
      let _that = this;
      return getBiPlatformList()
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            let translate = {};
            let arr = respData.data.filter(item => {
              if (item.value != "all") {
                translate[item.value] = item.name;
                return item;
              }
            });
            _that.biPlatformListSupAjax.data = arr;
            _that.translate.biPlatformList = translate;
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {});
    },
    getPageData() {
      let _that = this;
      let searchForm = _.cloneDeep(_that.alone.searchForm);
      let pageAjax = _that.pageAjax;

      if (pageAjax.loading || pageAjax.lock) {
        return;
      }

      let data = { ...searchForm.data };
      data.pageNo = _that.pageAjax.paging.current + 1;
      data.signStatus = _that.alone.signStatus;
      _that.pageAjax.loading = true;
      getActorList({ params: data })
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            _that.pageAjax.data = respData.data.list;
            _that.pageAjax.paging = {
              pages: respData.data.pagination.pages,
              current: respData.data.pagination.current,
              total: respData.data.pagination.total,
              pageSize: respData.data.pagination.pageSize
            };
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {
          _that.pageAjax.loading = false;
        });
    },
    rAgentReleaseActor(id) {
      let _that = this;
      console.log(id, _that);
      this.$confirm("你确定要释放此主播?", "释放主播提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          cancelBindActor({ anchorId: id }).then(resp => {
            let respData = resp.data || {};
            if (respData.code === _that.STATUS.success[0]) {
              _that.$message.success(respData.msg || "绑定成功");
              _that.pageAjax.paging.current =
                _that.pageAjax.paging.current > 0
                  ? _that.pageAjax.paging.current - 1
                  : 0;
              _that.getPageData();
            } else {
              _that.$message.error(respData.msg || "绑定失败");
            }
          });
        })
        .catch(() => {});
    },
    navToDetail(id) {
      this.$router.push({
        name: "agent_detail",
        query: {
          anchorId: id
        }
      });
    },
    navToLiveDetail(id) {
      this.$router.push({
        name: "agent_liveDetail",
        query: {
          anchorId: id
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  .s-search {
    border-bottom: 1px solid #eee;
  }
  .c-aside {
    .btn {
      margin-right: 20px;
    }
    .diy-uploadBtn {
      margin-right: 20px;
    }
  }
  .c-main {
    margin-top: 20px;
    .c-avatar {
      display: block;
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .c-pagination {
    margin-top: 20px;
    text-align: center;
  }
  .f-agentWish {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      overflow: auto;
    }
    .c-card {
      .c-item {
        padding-bottom: 20px;
        border-top: 1px solid #f5f7fa;
      }
      .c-UserInfo {
        position: relative;
        overflow: hidden;
        line-height: 25px;
      }
      .c-avatar {
        float: left;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .c-nameInfo {
        float: left;
        margin-left: 20px;
      }
      .c-copyBtn {
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        border: 1px solid #eee;
        padding: 10px 20px;
        border-radius: 20px;
      }
      .c-bid {
        overflow: hidden;
        line-height: 30px;
        img {
          float: left;
          width: 30px;
          height: 30px;
          margin-right: 20px;
        }
      }
    }
  }
  .f-agent {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      padding-top: 60px;
      overflow: auto;
    }
    .c-avatar {
      width: 80px;
      height: 80px;
    }
  }
}
</style>
<style lang="scss">
.page {
  .el-drawer__header {
    position: relative;
    z-index: 10;
  }
}
</style>
